package elements;

import java.awt.Polygon;

public class Rock extends Polygon {

	private static final long serialVersionUID = 1L;

	int uLeftXPos, uLeftYPos;
	int xDirection = 1;
	int yDirection = 1; // how fast

	int width = Board.boardWidth;
	int height = Board.boardHeight;

	int[] polyXArray, polyYArray;

	public static int[] sPolyXArray = { 10, 17, 26, 34, 27, 36, 26, 14, 8, 1,
			5, 1, 10 };
	public static int[] sPolyYArray = { 0, 5, 1, 8, 13, 20, 31, 28, 31, 22, 16,
			7, 0 };

	public Rock(int[] polyXArray, int[] polyYArray, int pointsInPoly,
			int randomStartXPos, int randomStartYPos) {

		super(polyXArray, polyYArray, pointsInPoly);
		// lets make it variable - level of difficulty
		this.xDirection = (int) (Math.random() * 4 + 1);
		this.yDirection = (int) (Math.random() * 4 + 1);

		this.uLeftXPos = randomStartXPos;
		this.uLeftYPos = randomStartYPos;
	}

	public void move() {
		int uLeftXPos = super.xpoints[0];
		int uLeftYPos = super.ypoints[0];

		// hit a wall
		if (uLeftXPos < 0 || (uLeftXPos + 25) > width) {
			xDirection = -xDirection;
		}
		if (uLeftYPos < 0 || (uLeftYPos + 50) > height) {
			yDirection = -yDirection;
		}

		for (int i = 0; i < super.xpoints.length; i++) {
			super.xpoints[i] += xDirection;
			super.ypoints[i] += yDirection;
		}
	}
	
	public static int[] getPolyXArray(int randomStartXPos){
		int[] tPolyXArray = sPolyXArray.clone();
		
		for(int i=0;i<tPolyXArray.length;i++){
			tPolyXArray[i]+=randomStartXPos;
		}
		return tPolyXArray;
	}
	
	public static int[] getPolyYArray(int randomStartYPos){
		int[] tPolyYArray = sPolyYArray.clone();
		
		for(int i=0;i<tPolyYArray.length;i++){
			tPolyYArray[i]+=randomStartYPos;
		}
		return tPolyYArray;
	}

}
